package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult listAll() {
        List<NursingPlanVo> list = new ArrayList<>();
        for (NursingPlan nursingPlan : nursingPlanService.listAll()) {
            list.add(BeanUtil.toBean(nursingPlan, NursingPlanVo.class));
            System.out.println(nursingPlan.getId());
        }

        return ResponseResult.success(list);
    }

    @PostMapping
    @ApiOperation("新增计划")
    public ResponseResult add(@ApiParam(value = "新增护理计划请求参数", required = true)
                              @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }

    @GetMapping("/search")
    @ApiOperation("分页查询护理计划列表")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage
            (@ApiParam(value = "护理计划名称") String name,
             @ApiParam(value = "状态: 0-禁用, 1-启用") Integer status,
             @ApiParam(value = "当前页码")
             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
             @ApiParam(value = "每页显示数量")
             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingPlanVo> nursingPlanPageInfo = nursingPlanService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingPlanPageInfo);

    }

    @ApiOperation("根据id查询护理计划数据")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getById
            (@ApiParam(value = "护理计划id", required = true)
             @PathVariable("id") long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @ApiOperation("修改护理计划")
    @PutMapping("/{id}")
    public ResponseResult update(
            @ApiParam(value = "请求参数dto类型", required = true)
            @RequestBody NursingPlanDto nursingPlanDto
    ) {
        nursingPlanService.update(nursingPlanDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id删除计划")
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable long id) {
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用计划")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult changeStatus(
            @PathVariable long id,
            @PathVariable long status) {
        nursingPlanService.changeStatus(id,status);
        return ResponseResult.success();
    }

}
